package com.powerbosframework.web.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.powerbosframework.context.ApplicatioinContextException;
import com.powerbosframework.context.ApplicationContext;
import com.powerbosframework.context.XmlApplicationContext;
import com.powerbosframework.log.LogFactory;
import com.powerbosframework.log.Logger;
import com.powerbosframework.web.action.GlobalMessage;

/**
 * WebApplicationContextServlet
 * 
 * @author youfu.wang
 * @version 1.0
 */
public class WebApplicationContextServlet extends HttpServlet {

	private static final long serialVersionUID = 4952612636757382137L;
	private ApplicationContext applicationContext;
	private static Logger log = LogFactory.getInstance();

	public WebApplicationContextServlet() {
		applicationContext= new XmlApplicationContext();
	}

	/**
	 * 销毁控制器所占内存
	 */
	public void destroy() {
		applicationContext.free();
	}

	/**
	 * 初始化应用上下文
	 */
	public void init() {	
		try {
			GlobalMessage.GLOBAL_PATH=getServletContext().getRealPath("");
			applicationContext.load();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ApplicatioinContextException e) {
			e.printStackTrace();
		}		
		String s = "com.powerbosframework.web.action.WebApplicationContextServlet";
		super.getServletContext().setAttribute(s, applicationContext);		
	}

	/**
	 * 处理GET请求方法
	 * 
	 * @param httpservletrequest
	 * @param httpservletresponse
	 * @throws IOException,
	 *             ServletException
	 */
	public void doGet(HttpServletRequest httpservletrequest,
			HttpServletResponse httpservletresponse) throws IOException,
			ServletException {
		
	}

	/**
	 * 处理POST请求方法
	 * 
	 * @param httpservletrequest
	 * @param httpservletresponse
	 * @throws IOException,
	 *             ServletException
	 */
	public void doPost(HttpServletRequest httpservletrequest,
			HttpServletResponse httpservletresponse) throws IOException,
			ServletException {
		
	}
}
